package com.yanfan.access.controller;

import java.util.Arrays;
import java.util.List;
import javax.validation.Valid;
import javax.servlet.http.HttpServletResponse;
import com.yanfan.common.utils.DateUtils;
import com.yanfan.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.access.domain.NjAccessChannelInfo;
import com.yanfan.access.service.INjAccessChannelInfoService;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.common.core.page.TableDataInfo;

/**
 * 通道信息Controller
 *
 * @author genluo
 * @date 2024-10-30
 */
@Api(tags = "通道信息")
@RestController
@RequestMapping("/access/channelInfo")
public class NjAccessChannelInfoController extends BaseController {
    @Autowired
    private INjAccessChannelInfoService njAccessChannelInfoService;

    /**
     * 查询通道信息列表
     */
    @ApiOperation("通道信息分页列表")
    @PreAuthorize("@ss.hasPermi('access:channelInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjAccessChannelInfo njAccessChannelInfo) {
        startPage();
        List<NjAccessChannelInfo> list = njAccessChannelInfoService.queryPageList(njAccessChannelInfo);
        return getDataTable(list);
    }

    /**
     * 导出通道信息列表
     */
    @ApiOperation("导出通道信息列表")
    @PreAuthorize("@ss.hasPermi('access:channelInfo:export')")
    @Log(title = "通道信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjAccessChannelInfo njAccessChannelInfo) {
        List<NjAccessChannelInfo> list = njAccessChannelInfoService.queryPageList(njAccessChannelInfo);
        ExcelUtil<NjAccessChannelInfo> util = new ExcelUtil<NjAccessChannelInfo>(NjAccessChannelInfo.class);
        util.exportExcel(response, list, "通道信息数据");
    }

    /**
     * 获取通道信息详细信息
     */
    @ApiOperation("获取通道信息详细信息")
    @PreAuthorize("@ss.hasPermi('access:channelInfo:query')")
    @GetMapping(value = "/{channelCode}")
    public AjaxResult getInfo(@PathVariable("channelCode") String channelCode) {
        return success(njAccessChannelInfoService.getById(channelCode));
    }

    /**
     * 新增通道信息
     */
    @ApiOperation("新增通道信息")
    @PreAuthorize("@ss.hasPermi('access:channelInfo:add')")
    @Log(title = "通道信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody NjAccessChannelInfo njAccessChannelInfo) {
        njAccessChannelInfo.setCreateTime(DateUtils.getTimestamp());
        return toAjax(njAccessChannelInfoService.save(njAccessChannelInfo));
    }

    /**
     * 修改通道信息
     */
    @ApiOperation("修改通道信息")
    @PreAuthorize("@ss.hasPermi('access:channelInfo:edit')")
    @Log(title = "通道信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody NjAccessChannelInfo njAccessChannelInfo) {
        njAccessChannelInfo.setUpdateTime(DateUtils.getTimestamp());
        return toAjax(njAccessChannelInfoService.updateById(njAccessChannelInfo));
    }

    /**
     * 删除通道信息
     */
    @ApiOperation("删除通道信息")
    @PreAuthorize("@ss.hasPermi('access:channelInfo:remove')")
    @Log(title = "通道信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{channelCodes}")
    public AjaxResult remove(@PathVariable String[] channelCodes) {
        return toAjax(njAccessChannelInfoService.removeBatchByIds(Arrays.asList(channelCodes)));
    }
}
